package com.centling.bluecollar.login.entity;

import java.util.HashSet;  
import java.util.Set;  
  
import javax.persistence.Column;  
import javax.persistence.Entity;  
import javax.persistence.FetchType;  
import javax.persistence.GeneratedValue;  
import javax.persistence.Id;  
import javax.persistence.JoinColumn;  
import javax.persistence.JoinTable;  
import javax.persistence.ManyToMany;  
import javax.persistence.Table;  
  
import org.hibernate.annotations.GenericGenerator;  
  
@Entity  
@Table(name = "roles", catalog = "mis2013")  
public class Roles {  
    private String id;  
    private String rolename;  
    private String description;  
    private Set<User> users = new HashSet<User>();  
    private Set<Perm> perms = new HashSet<Perm>();  
  
    @GenericGenerator(name = "generator", strategy = "uuid.hex")  
    @Id  
    @GeneratedValue(generator = "generator")  
    @Column(name = "id", unique = true, nullable = false, length = 36)  
    public String getId() {  
        return id;  
    }  
  
    public void setId(String id) {  
        this.id = id;  
    }  
  
    @Column(name = "rolename", nullable = false, length = 50)  
    public String getRolename() {  
        return rolename;  
    }  
  
    public void setRolename(String rolename) {  
        this.rolename = rolename;  
    }  
  
    @Column(name = "description", length = 255)  
    public String getDescription() {  
        return description;  
    }  
  
    public void setDescription(String description) {  
        this.description = description;  
    }  
  
    @ManyToMany(mappedBy = "roles")  
    public Set<User> getUsers() {  
        return users;  
    }  
  
    public void setUsers(Set<User> users) {  
        this.users = users;  
    }  
  
    @ManyToMany(targetEntity = Perm.class, fetch = FetchType.EAGER)  
    @JoinTable(name = "roles_perms", joinColumns = @JoinColumn(name = "roles_id"), inverseJoinColumns = @JoinColumn(name = "perms_id"))  
    public Set<Perm> getPerms() {  
        return perms;  
    }  
  
    public void setPerms(Set<Perm> perms) {  
        this.perms = perms;  
    }  
}  
